#include "microbialserver.h"
#include "ui_microbialserver.h"

#include "Environment.h"

#include <QImage>
#include <QPainter>
#include <QGraphicsScene>
#include <QGraphicsPixmapItem>
#include <QPixmap>
#include <QTime>

MicrobialServer::MicrobialServer(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MicrobialServer)
{
    QTime midnight(0, 0, 0);
    qsrand(midnight.secsTo(QTime::currentTime()));

    ui->setupUi(this);

    QGraphicsScene *scene = new QGraphicsScene(0, 0, 800, 600, this);

    ui->graphicsView->setScene(scene);

    //QImage image(800, 600, QImage::Format_ARGB32);
    //QRadialGradient gradRed(50, 50, 50, 50, 50);
    //gradRed.setColorAt(0, QColor(0xAA, 0x00, 0x00, 255));
    //gradRed.setColorAt(0.3, QColor(0xFF, 0x00, 0x00, 100));
    //gradRed.setColorAt(0.8, QColor(0xAA, 0x00, 0x00, 0));

    //QRadialGradient gradBlue(75, 75, 50, 50, 50);
    //gradBlue.setColorAt(0, QColor(0x00, 0xAA, 0x00, 255));
    //gradBlue.setColorAt(0.3, QColor(0x00, 0xFF, 0x00, 100));
    //gradBlue.setColorAt(0.8, QColor(0x00, 0xAA, 0x00, 0));

    //QImage *image = new QImage(800, 600, QImage::Format_ARGB32);
    //QPainter painter(image);
    //QBrush brush(QColor(0x00, 0x00, 0x00, 255));
    //QBrush brushRed(gradRed);
    //QBrush brushBlue(gradBlue);

    //painter.fillRect(0, 0, 800, 600, QBrush(QColor(0x00, 0x00, 0x00, 255)));
    //painter.setCompositionMode(QPainter::RasterOp_SourceOrDestination);
    //painter.setPen(Qt::NoPen);
    //painter.setBrush(gradRed);
    //painter.drawEllipse(QPoint(50, 50), 50, 50);

    //painter.setBrush(gradBlue);
    //painter.drawEllipse(QPoint(75, 75), 50, 50);

    Environment env(800, 600, 50, 50, 50);

    env.generateEnvironment();

    QGraphicsPixmapItem *item = new QGraphicsPixmapItem(QPixmap::fromImage(*env.getImage()));

    scene->addItem(item);

    item->setX(0);
    item->setY(0);
}

MicrobialServer::~MicrobialServer()
{
    delete ui;
}
